#include <bits/stdc++.h>
using namespace std;
struct stu{
    string name;
    int sex;
    bool flag = true;
};
int main() {
    int n;
    cin>>n;
    stu arr[n];
    for (int i = 0; i < n; ++i) {
        cin>>arr[i].sex>>arr[i].name;
    }
    for (int i = 0; i < n/2; ++i) {
        int j = n-1;
        while (true){
            if(arr[i].sex!=arr[j].sex&&arr[j].flag){
                arr[j].flag = false;
                break;
            }
            j--;
        }
        cout<<arr[i].name<<" "<<arr[j].name<<endl;
    }
}
